package net.qiqbframework.modelling.command.voucher;

import net.qiqbframework.common.utils.StringUtil;

import java.lang.reflect.Member;
import java.lang.reflect.Method;
import java.util.Optional;

public class MethodBizIdentifierVoucherModel<ID, C> implements BizIdentifierVoucherModel<ID, C> {

    private final Method method;

    private final Class<ID> bizIdDeclaredType;


    private final String routingBizIdentifierName;

    public MethodBizIdentifierVoucherModel(Method method) {
        this(method, null);
    }

    public MethodBizIdentifierVoucherModel(Method method, String routingBizIdentifierName) {
        this.method = method;
        this.bizIdDeclaredType = (Class<ID>) this.method.getDeclaringClass();
        // get 取消
        this.routingBizIdentifierName = StringUtil.isEmpty(routingBizIdentifierName) ? routingBizIdentifierName : method.getName();
    }

    @Override
    public Class<ID> declaredType() {
        return bizIdDeclaredType;
    }

    @Override
    public Member member() {
        return method;
    }

    @Override
    public String routingBizIdentifierName() {
        return routingBizIdentifierName;
    }

    @Override
    public Optional<ID> bizIdentifierVoucher(C command) {
        return Optional.empty();
    }

    @Override
    public int priority() {
        return 0;
    }
}
